<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('流程审批')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="col-sm-8">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-sjcontract-add" th:object="${obj}">
    	<h4 class="form-header h4">基本信息</h4>
    	<input name="approvename" id="approvename" type="hidden" th:value="${approvename}" />
    	<div class="form-group">    
            <label class="col-sm-2 control-label ">对接部门：</label>
            <div class="col-sm-4">
                <input name="deptName" class="form-control" type="text" th:field="*{deptName}" autoComplete="off" readonly="readonly" >
            </div>
            <label class="col-sm-2 control-label ">对接人：</label>
            <div class="col-sm-4">
                <input name="owner" class="form-control" type="text" th:field="*{owner}" readonly="readonly" autoComplete="off" >
            </div>
        </div>
        	<div class="form-group">    
               <label class="col-sm-2 control-label ">投标项目名称：</label>
               <div class="col-sm-4">
                   <input name="projectName" class="form-control" th:field="*{projectName}" type="text" readonly="readonly" autoComplete="off">
               </div>
               <label class="col-sm-2 control-label ">开标地点：</label>
               <div class="col-sm-4">
                   <input name="kbdd" class="form-control" th:field="*{kbdd}" type="text" readonly="readonly" autoComplete="off">
               </div>
           </div>
           <div class="form-group">    
			<label class="col-sm-2 control-label ">商机跟踪：</label>
               <div class="col-sm-4">
                   <input name="chanceName" class="form-control" th:field="*{chanceName}" type="text" readonly="readonly" autoComplete="off">
               </div>
               <label class="col-sm-2 control-label ">开标日期：</label>
               <div class="col-sm-4">
                   <div class="input-group date">
                       <input name="kbAt" th:value="${#dates.format(obj.kbAt, 'yyyy-MM-dd')}" readonly="readonly" class="form-control" placeholder="yyyy-MM-dd" type="text" >
                       <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                   </div>
               </div>
           </div>
           <div class="form-group">    
               <label class="col-sm-2 control-label ">投标控制价：</label>
               <div class="col-sm-4">
                   <input name="tbkzj" th:field="*{tbkzj}" class="form-control" type="number" readonly="readonly" autoComplete="off">
               </div>
               <label class="col-sm-2 control-label ">投标负责人：</label>
               <div class="col-sm-4">
                   <input name="tbfzr" th:field="*{tbfzr}" class="form-control" th:value="${owner}" type="text" readonly="readonly" autoComplete="off">
               </div>
           </div>
           <div class="form-group">    
               <label class="col-sm-2 control-label ">保证金金额：</label>
               <div class="col-sm-4">
                   <input name="bzjje" th:field="*{bzjje}" class="form-control" type="number" readonly="readonly" autoComplete="off">
               </div>
               <label class="col-sm-2 control-label ">投标状态：</label>
               <div class="col-sm-4">
                   <select name="status" th:field="*{status}" class="form-control" th:with="type=${@dict.getType('sj_bidding_status')}" readonly="readonly">
	                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	            </select>
               </div>
           </div>
           <div class="form-group">    
               <label class="col-sm-2 control-label ">投标类型：</label>
               <div class="col-sm-4">
                   <select name="tbType" th:field="*{tbType}" class="form-control" th:with="type=${@dict.getType('sj_tbType')}" readonly="readonly">
	                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	            </select>
               </div>
               <label class="col-sm-2 control-label ">项目类型：</label>
               <div class="col-sm-4">
                   <select name="proType" th:field="*{proType}" class="form-control" th:with="type=${@dict.getType('sj_proType')}" readonly="readonly">
	                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
	            </select>
               </div>
           </div>
           <div class="form-group">    
                <label class="col-sm-2 control-label">联合体方：</label>
                <div class="col-sm-4">
                    <input name="lhtf" th:field="*{lhtf}" class="form-control" type="text" autoComplete="off" readonly="readonly">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">备注：</label>
                <div class="col-sm-10">
                    <textarea name="memo" class="form-control" autoComplete="off" readonly="readonly">[[*{memo}]]</textarea>
                </div>
            </div>
        <!--  -->
        <div class="form-group">
        	<input type="hidden" id="zbFile" name="zbFile" th:field="*{zbFile}" />
            <input type="hidden" id="zbFilevo" name="zbFilevo" th:value="${zbFilevo}" />
            <label class="col-sm-2 control-label">招标文件：</label>
            <div class="col-sm-10" style="margin-top: 8px;" id="zbFilelink">
            </div>
        </div>
        <h4 class="form-header h4" style="margin-top: 8px;margin-bottom: 0px;">表单项</h4>
            <div class="row" >
                <div class="col-sm-12">
				    <table id="bootstrap-table"></table>
                </div>
            </div>
        <h4 class="form-header h4" style="margin-top: 18px;">审核信息</h4>
        <div class="form-group">
            <label class="col-sm-2 control-label ">审批结果：</label>
            <div class="col-sm-4">
                <label class="radio-box">
                    <input type="radio" checked="" value="true" name="level1approve">同意</label>
                <label class="radio-box">
                    <input type="radio" value="false" name="level1approve">拒绝</label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">审批意见：</label>
            <div class="col-sm-10">
                <textarea rows="5" name="fwshyj" class="form-control" required></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-3 col-sm-offset-3">
                <input type="hidden"  name="taskid" id="taskid" th:value="${taskid}">
                <input type="hidden"  name="biddingstatus" id="biddingstatus" th:value="1">
                <input type="hidden"  name="id" id="id" th:value="${obj.id}">
                <button class="btn btn-primary" onclick="submitHandler()" type="button"><i class="fa fa-check"></i>&nbsp;提交</button>
            </div>
        </div>
    </form>
</div>
</div>
<div id="ibox-content" class="col-sm-4">
    <div id="vertical-timeline" class="vertical-container dark-timeline">
    </div>
</div>
</body>
<th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: jasny-bootstrap-js" />
    <th:block th:include="include :: bootstrap-suggest-js" />
    <th:block th:include="include :: bootstrap-typeahead-js" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script th:src="@{/ruoyi/base64.min.js?v=20231208}"></script>
    <script th:src="@{/js/jquery.tmpl.js}"></script>
<script th:inline="javascript">
    var prefix = ctx + "task/manage"
    $("#form-sjcontract-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
    	if ($.validate.form()) {
        var taskid = $("#taskid").val();
        var check = document.querySelector("input[name='level1approve']:checked").value;
        if(check=="false"){
        	$("#biddingstatus").val(4);
        }else{
        	$("#biddingstatus").val(2);
        }
        var comment = $("textarea[name=fwshyj]").val();
        
        $.operate.save("edit4check", $('#form-sjcontract-add').serialize(), function(){
        	var json = {"level1approve": check, "level2": $("#approvename").val(), "spusername": $("#approvename").val(), "comment": comment};
	        $.ajax({
	            url : prefix + "/completeTask/" + taskid,
	            type : "POST",
	            data : JSON.stringify(json), //转JSON字符串
	            dataType: 'json',
	            contentType:'application/json;charset=UTF-8', //contentType很重要
	            success : function(result) {
	                $.modal.msg("办理成功");
	                const parent = window.parent;
	                // 我的待办
	                const myToDoIframe = parent.document.querySelector("iframe[src='/task/manage/mytask']");
	                // 我的全部待办
	                const myAllToDoIframe = parent.document.querySelector("iframe[src='/task/manage/alltasks']");
	                myToDoIframe && myToDoIframe.contentWindow.location.reload(true);
	                myAllToDoIframe && myAllToDoIframe.contentWindow.location.reload(true);
	                $.modal.closeTab();
	            }
	        });
	        
        });
    	}
    }

    $(document).ready(function(){
        // 获取时间轴
        $.get(prefix + "/history/" + $("#taskid").val(), function(data){
            for (var a = 0; a < data.length ; a++) {
                $("#vertical-timeline").append("<div class=\"vertical-timeline-block\"><div class=\"vertical-timeline-icon lazur-bg\">" +
                    "<i class=\"fa fa-briefcase\"></i></div>" +
                    "<div class=\"vertical-timeline-content\">" +
                    "<span class=\"vertical-date\">开始 <small>" + data[a].startTime + "</small></span><br>" +
                    "<h2><b>" + data[a].assignee + ":</b>" + data[a].taskName + "</h2>" +
                    "<p>" + (data[a].comment || "-") + "</p>" +
                    "<span class=\"vertical-date\">结束 <small>" + (data[a].endTime || "-") + "</small></span>" +
                    "</div>" +
                    "</div>");
            }
        });
    });
    
    $(function() {
		var zilwj = $("#zbFilevo").val();
    	
    	var n=zilwj.split(",");
    	for(var i=0;i<n.length;i++){
//     		var url = "http://lkgnews.cn:8012/onlinePreview?url="+encodeURIComponent(Base64.encode(n[i]));
    		var url = n[i];
    		$("#zbFilelink").append("<a href='"+url+"' target='_blank' >"+n[i]+"</a><br>");
    	}
    	
    	// 多图上传
       $("#multipleFile").fileinput({
           uploadUrl: "/common/uploads",
           uploadAsync: false,
           showClose: false,
           showCancel: false,
           dropZoneEnabled: false,
           buttonLabelClass: ''
       }).on('filebatchuploadsuccess', function (event, data, previewId, index) {
       	var rsp = data.response;
           log.info("reutrn fileNames：" + rsp.fileNames)
		   $("#zbFile").val(rsp.fileNames);
       }).on('fileremoved', function (event, id, index) {
           $("input[name='" + event.currentTarget.id + "']").val('')
       })
       
    });
    
    $("input[name='tbjzAt']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='kbAt']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='bxfkAt']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $("input[name='yjtkAt']").datetimepicker({
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true
    });

    $(function() {
    	var data = [[${obj.items}]];
    	// 初始化数据, 可以由后台传过来
	    var options = {
	    	data: data,
            pagination: false,
	        showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            sidePagination: "client",
	        columns: [
	        {
	        	field: 'index',
	        	align: 'center',
	        	title: "序号",
	        	width: 50,
                formatter: function (value, row, index) {
                	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                	var columnId = $.common.sprintf("<input type='hidden' name='items[%s].xuh' value='%s'>", index, row.id);
                	return columnIndex + $.table.serialNumber(index) + columnId;
                }
            },
	        {
	            field: 'name',
	            align: 'center',
	            title: '姓名',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input class='form-control namecount' type='hidden' autoComplete='off' name='items[%s].name' value='%s'>", index, value);
	        		return html+value;
                }
	        },
	        {
	            field: 'gwname',
	            align: 'center',
	            title: '岗位',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input class='form-control namecount' type='hidden' autoComplete='off' name='items[%s].gwname' value='%s'>", index, value);
	        		return html+value;
                }
	        },
	        {
	            field: 'je',
	            align: 'center',
	            title: '金额',
	            formatter: function(value, row, index) {
	            	var html = $.common.sprintf("<input class='form-control jecount' type='hidden' autoComplete='off' name='items[%s].je' value='%s'>", index, value);
	        		return html+value;
                }
	        }]
	    };
	    $.table.init(options);
	});
    
    $.validator.addMethod("namecount", function(value, element) {
        return !this.optional(element);
    }, "姓名必填。");
    $.validator.addMethod("gwnamecount", function(value, element) {
        return !this.optional(element);
    }, "岗位必填。");
    $.validator.addMethod("jecount", function(value, element) {
        return !this.optional(element) && (value <= 10000000 && value >= 1);
    }, "金额长度区间1-10000000。");
    
    function addRow() {
    	var count = $("#" + table.options.id).bootstrapTable('getData').length;
    	var row = {
            index: $.table.serialNumber(count),
            name: "",
            je: "1",
            gwname: ""
        }
    	sub.addColumn(row);
    }
    
  //选择用户tbfzr
	function selecttbfzr() {
		var options = {
	       title: '选择用户',
	       url: "/sj/config/invokeUser",
	       width: '1000',
	       height: '670',
	       callBack: doSubmittbfzr
	    };
	    $.modal.openOptions(options);
	}
 	
	function doSubmittbfzr(index, layero){
        var rows = layero.find("iframe")[0].contentWindow.getSelections();
        if (rows.length == 0) {
            $.modal.alertWarning("请选择一条记录！");
            return;
        }
        
        if (rows.length > 1) {
            $.modal.alertWarning("请勿选择多条记录！");
            return;
        }
        
        $("#tbfzrId").val(rows[0].userId);
        $("#tbfzr").val(rows[0].userName);
        $("#tbfzrStr").val(rows[0].userName);
        $.modal.closeAll();
    }
</script>
</body>
</html>

<!-- 岗位 -->
<script id="itemGw" type="text/x-jquery-tmpl">
<div>
<select class='form-control' name='items[${index}].gwname' >
	<option value="投标制作人" {{if type==="投标制作人"}}selected{{/if}}>投标制作人</option>
    <option value="初审人" {{if type==="初审人"}}selected{{/if}}>初审人</option>
	<option value="复审人" {{if type==="复审人"}}selected{{/if}}>复审人</option>
	<option value="审定人" {{if type==="审定人"}}selected{{/if}}>审定人</option>
</select>
</div>
</script>